<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>${SYSTEM_NAME}</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/static/layuiadmin/layui/css/layui.css?v=${FILE_VERSION}" media="all">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/static/layuiadmin/style/admin.css?v=${FILE_VERSION}" media="all">
</head>
<body>
	<div class="layui-fluid">
       	<div class="layui-card">
         	<div class="layui-card-header">系统回收站</div>
         	<div class="layui-card-body">
				<div class="layui-form layer-query">
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">资源名称：</label>
							<div class="layui-input-inline">
								<input type="text" placeholder="请输入资源名称" id="tableComment" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<button class="layui-btn layui-btn-primary layui-border-blue" onclick="reload()">查询</button>
						</div>
					</div>
				</div>
				<hr class="layui-bg-green">
				<div class="layui-form-item">
					<div class="layui-inline">
						<button class="layui-btn layui-btn-primary layui-border-blue" onclick="initSystemRecycle()">回收站初始化</button>
					</div>
				</div>
				<div class="layui-bg-cyan" style="padding: 5px">点击“系统资源名称”表格数据可进行资源名称修改，点击“是否开放”按钮可调整开放状态</div>
           		<table class="layui-table" lay-filter="tableList" id="layerTable">
				</table>
         	</div>
       	</div>
  	</div>

	<script type="text/html" id="barTpl">
		{{#  if(d.isOpen=='1'){ }}
		<a class="layui-btn layui-btn-primary layui-border-blue layui-btn-xs" lay-event="setQueryCol">设置查询列</a>
		{{#  } }}
	</script>
	<script type="text/html" id="isOpenTpl">
		<input type="checkbox" name="isOpen" lay-skin="switch" lay-text="是|否" lay-filter="isOpenFilter"
			   value="{{ d.isOpen }}"  data-json="{{ encodeURIComponent(JSON.stringify(d)) }}" {{ d.isOpen == '1' ? 'checked' : '' }}>
	</script>

	<script src="${pageContext.request.contextPath}/static/js/common-2.0.0.js?v=${FILE_VERSION}"></script>
  	<script src="${pageContext.request.contextPath}/static/layuiadmin/layui/layui.js?v=${FILE_VERSION}"></script>
  	<script src="${pageContext.request.contextPath}/static/js/jquery-3.3.1.min.js?v=${FILE_VERSION}"></script>
	<script src="${pageContext.request.contextPath}/static/js/common/core-2.0.0.js?v=${FILE_VERSION}"></script>
  	<script>
  		var table;
	  	layui.config({
	  		base: getContextPath() + '/static/layuiadmin/' //静态资源所在路径
	  	}).extend({
	    	index: 'lib/index' //主入口模块
	  	}).use(['table', 'element', 'form'], function() {
	  		var form = layui.form;
			table = layui.table;
			table.render({ 
				elem : '#layerTable',
				even : "true",
				height: 'full-260',
				limit : 30,
				limits : [ 10, 20, 30 ],
				id : 'tableList',
				url : getContextPath() + '/sys/recycle/list/listInfo',
				page : true,
				method : 'post',
				cols : [[
					{field : 'tableComment', width : 200, title : '系统资源名称', edit: 'text'}
					,{field : 'tableName', width : 200,title : '系统表名'}
					,{field:'isOpenName', minWidth:200,title:"回收站是否开放",templet: '#isOpenTpl'}
					,{fixed: 'right', width:200, align:'center',title:"操作", toolbar: '#barTpl'}
				]],
				request : {
					pageName : 'current',
					limitName : 'size'
				}
			});

			//监听工具条
			table.on('tool(tableList)', function(obj) {
				var data = obj.data;
				if (obj.event === 'setQueryCol') {
					setQueryCol(data.tableName,data.tableComment);
				}
			});

			table.on('edit(tableList)', function(obj){
				var tableComment = obj.value;
				if(tableComment.length < 0){
					layer.msg("系统资源名称不能为空");
					return;
				}
				$ajax({
					url : "/sys/recycle/updateTableComment",
					data:{
						"id" : obj.data.id,
						"tableComment": tableComment
					},
					succCallback: function (json) {
						if(json.code == 0){
							layer.msg("系统资源名称更新成功");
						}
					}
				});
			});

			//监听操作
			form.on('switch(isOpenFilter)', function(obj){
				var dataJson = JSON.parse(decodeURIComponent($(this).data('json')));
				var id = dataJson.id;
				var isOpen = obj.elem.checked ? "1" : "0";
				$ajax({
					url: '/sys/recycle/updateIsOpen',
					isShowLayer:false,
					data :  {
						"id" : id,
						"isOpen" : isOpen
					},
					succCallback: function (json) {
						if(json.code == 0){
							table.clearCacheKey(dataJson);
							var elem= $(".layui-table-main tr[data-index='"+(dataJson.LAY_INDEX-1)+"'] .layui-table-col-special .layui-table-cell");
							if(isOpen== '1'){
								elem.append('<a class="layui-btn layui-btn-primary layui-border-blue layui-btn-xs" lay-event="setQueryCol">设置查询列</a>');
							}else{
								elem.empty();
							}
							layer.msg("回收站是否开启调整成功");
						}
					}
				});
			});

		});

		function reload() {
			table.reload('tableList',{
				where:{
				"tableComment": $("#tableComment").val()
				}
			});
		}

		function initSystemRecycle(){
			layer.confirm('您确定要初始化回收站资源吗?', function(index){
				$ajax({
					url: "/sys/recycle/initSystemRecycle",
					succCallback: function (json) {
						if(json.code == 0)
							reload();
					}
				});
			});
		}

		function setQueryCol(tableName,tableComment){
			var url = getContextPath() + "/sys/recycle/setQueryCol?tableName=" + tableName;
			layer.open({
				title : "设置查询列【"+tableComment+"】",
				type: 2,
				area: ['95%', '95%'],
				anim: 2,
				content: [url, 'yes']
			});
		}
  	</script>
</body>
</html>
